package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqVar;
import cloud.maque.admin.service.MqVarService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 参数接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/var")
@Api(tags = "运维-参数接口")
public class VarController {


    @Autowired
    MqVarService varService;


    @PostMapping("/page")
    @ApiOperation(value = "查询")
    @TenantQuery
    public ResponseBodyVo<PageInfo<MqVar>> page(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqVar> pageReq) {
        return ResponseBodyVo.Success(varService.page(pageReq));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情")
    public ResponseBodyVo<MqVar> Detail(@PathVariable("id") String varId) {
        return ResponseBodyVo.Success(varService.getById(varId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增或修改")
    public ResponseBodyVo<MqVar> save(@RequestBody @ApiParam("内容") MqVar var) {

        return ResponseBodyVo.Success(varService.saveVar(var));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@PathVariable("id") String varId, @TenantId String tenantId) {
        return ResponseBodyVo.Success(varService.delete(varId, tenantId));
    }


    @GetMapping("/detailByKey")
    @ApiOperation(value = "根据Key获取内容")
    public ResponseBodyVo<MqVar> DetailByKey(@RequestParam("tenantId") String tenantId, @RequestParam("key") String key) {
        return ResponseBodyVo.Success(varService.getByKey(tenantId, key));
    }

}
